package io.github.maojian.bianrysearch;

import org.junit.Test;

import java.util.Arrays;

/**
 * @Auther: jian.mao
 * @Date: 2022/5/20 17:29
 * @Description:
 */
public class Q1317 {
    public int[] kWeakestRows(int[][] mat, int k) {
        int length = mat.length;
        int n = mat[0].length;
        int[][] tempArr = new int[length][2];
        for (int i = 0; i < length; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                if (mat[i][j] == 0) continue;
                sum += 1;
            }
            tempArr[i][0] = sum;
            tempArr[i][1] = i;
        }
        Arrays.sort(tempArr, (o1, o2) -> o1[0] - o2[0]);
        int[] result = new int[k];
        for (int i = 0; i < k; i++) {
            result[i] = tempArr[i][1];
        }
        return result;
    }


    @Test
    public void test() {
        int arrs[][] = new int[][]{
                {1, 1, 0, 0, 0},
                {1, 1, 1, 1, 0},
                {1, 0, 0, 0, 0},
                {1, 1, 0, 0, 0},
                {1, 1, 1, 1, 1}
        };
        Arrays.stream(kWeakestRows(arrs, 3)).forEach(System.out::println);
    }
}
